package cn.com.generaldata.os.report.xml;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.com.generaldata.os.pojo.mvc.Report;
import cn.com.generaldata.os.pojo.mvc.Row;
import cn.com.generaldata.os.util.XMLComplexityIntf;
import cn.com.generaldata.os.util.XMLUtil;

public class ReportImporter {
	private static Log log = LogFactory.getLog(ReportImporter.class);
	private static final String log_header = "[Report][ReportImporter]";

	public static Report importReport(String fileName) {
		try {
			Report report = (Report) XMLUtil.loadFromXMLFile(fileName, new XMLComplexityIntf() {

				@SuppressWarnings("rawtypes")
				@Override
				public Map<String, Class> generateAliasMap() {
					Map<String, Class> map = new HashMap<String, Class>();
					map.put("Report", Report.class);
					map.put("Row", Row.class);
					return map;
				}

			});

			return report;
		} catch (Exception ex) {
			log.error(log_header + "[importReport]Exception: ", ex);
			return null;
		}
	}
}
